﻿using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevSamPle.FormPlugin
{
    [Description("【表单插件】生产用料清单，物料名称是贴片电容的，前景色设置为红色"), HotUpdate]
    public class PPBomSetColor : AbstractDynamicFormPlugIn
    {
        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
            var fieldKey = "FMustQty";
            var grid = this.View.GetControl<EntryGrid>("FEntity");
            DynamicObjectCollection eRows = this.Model.DataObject["PPBomEntry"] as DynamicObjectCollection;
            int i = 0;
            foreach (var row in eRows)
            {
                DynamicObject material = row["MaterialID"] as DynamicObject;
                string materialName = material["Name"].ToString();
                if (materialName.Contains("贴片电容"))
                {
                    grid.SetForecolor(fieldKey, "#ff0000", i);
                    //第几行用什么颜色
                    List<KeyValuePair<int, string>> colors = new List<KeyValuePair<int, string>>();
                    colors.Add(new KeyValuePair<int, string>(i, "#ead1dc")); //第二行
                    grid.SetRowBackcolor(colors);
                }
                i++;
            }
        }
    }
}
